{% set page_name = "用户管理" %}
{% import "components/nothing.html" as nothing with context %}
{% import "components/paginator.html" as paginator with context %}
{% extends "manage_base.html" %}
{% block manage_content %}
<div class="section">
    <div class="section__header">
        <h1 class="section__title">{{ _('用户管理') }}</h1>
        <div class="section__tools">
            <a class="primary rounded button" href="{{ url('manage_changeuname') }}">{{ _('修改用户名') }}</a>
        </div>
    </div>
    <div class="section__body no-padding">
        <table class="data-table">
            <colgroup>
                <col class="col--uid" style="width:5rem">
                <col class="col--user" style="width:12rem">
                <col class="col--displayName" style="width:8rem">
                <col class="col--school" style="width:8rem">
                <col class="col--groups" style="width:8rem">
                <col class="col--bio">
                <col class="col--status" style="width:8rem">
            </colgroup>
            <thead>
                <tr>
                    <th>{{ _('User ID') }}</th>
                    <th>{{ _('Username') }}</th>
                    <th>{{ _('Display Name') }}</th>
                    <th>{{ _('School') }}</th>
                    <form method="get" class="inline">
                      <th>
                        <select name="groupName" class="select" onchange="this.form.submit()">
                          <option value="">{{ _('所有小组') }}</option>
                          {% for group in groups %}
                            <option value="{{ group.name }}" {% if groupName == group.name %}selected{% endif %}>
                              {{ group.name }} ({{ group.uids.length }} {{ _('users') }})
                            </option>
                          {% endfor %}
                        </select>
                      </th>
                      <th>{{ _('Bio') }}</th>
                      <th>
                        <select name="banStatus" class="select" onchange="this.form.submit()">
                          <option value="">{{ _('所有状态') }}</option>
                            <option value="active" {% if banStatus == 'active' %}selected{% endif %}>{{ _('未封禁') }}</option>
                            <option value="banned" {% if banStatus == 'banned' %}selected{% endif %}>{{ _('已封禁') }}</option>
                        </select>
                      </th>
                    </form> 
                </tr>
            </thead>
            <tbody>
                {%- for udoc in udocs -%}
                <tr>
                    <td>{{ udoc._id }}</td>
                    <td>{{ user.render_inline(udoc) }}</td>
                    <td>{{ udoc.displayName }}</td>
                    <td>{{ udoc.school }}</td>
                    <td>
                        {%- for group in groups -%}
                        {%- if udoc._id in group.uids -%}
                        {{ group.name }}{{ ' ' }}
                        {%- endif -%}
                        {%- endfor -%}
                    </td>
                    <td>{{ udoc.bio|default('')|truncate(64, true)|markdownInline|safe }}</td>
                    <td>
                        {% if udoc.hasPriv(PRIV.PRIV_USER_PROFILE) %}
                            {{ _('未封禁') }}
                            <form method="post" style="display:inline">
                                <input type="hidden" name="uid" value="{{ udoc._id }}">
                                <input type="hidden" name="uname" value="{{ udoc.uname }}">
                                <button type="submit" class="typo-a">
                                    {{ _('封禁') }}
                                </button>
                            </form>
                        {% else %}
                            {{ _('已封禁') }}
                        {% endif %}
                    </td>
                </tr>
                {%- endfor -%}
            </tbody>
        </table>
        {{ paginator.render(page, upcount,add_qs=(('groupName=' + groupName if groupName else '') + ('&banStatus=' + banStatus) if banStatus else '')) }}
    </div>
</div>
{% endblock %}